<template>
  <div class="root">
    <el-form label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="username"/>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="password"/>
      </el-form-item>
      <el-form-item class="last-item">
        <el-button type="primary" @click="login">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      username: '',
      password: '',
    }
  },
  methods: {
    login() {
      if (!this.username) {
        this.$message.error('请输入用户名');
        return;
      }
      if (!this.password) {
        this.$message.error('请输入密码');
        return;
      }
      this.$JIM.login(this.username, this.password, () => {
        this.$message.success('登录成功');
        this.$router.replace('/main')
      }, (data) => {
        this.$message.error(`code:${data.code},\xa0\xa0\xa0message:${data.message}`);
      })

    },

  }
}
</script>

<style scoped>
.root {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.el-form {
  width: 500px;
}

.last-item {
  margin-bottom: 0;
}

.el-button {
  width: 100%;
}
</style>